<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/12/23
  Time: 1:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>emp表</title>
    <script src="/static/jquery-3.6.1.min.js"></script>
</head>
<body>
    <div align="center">
        <form id="addform">
            名字：<input type="text" name="name">
            年龄：<input type="text" name="age">
            <input type="button" onclick="add()" value="添加">
        </form>
    </div>

    <table border="1" rules="all" align="center">
        <tr>
            <th>id</th>
            <th>name</th>
            <th>age</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${listEmp}" var="emp" varStatus="d">
            <tr>
                <td>${emp.id}</td>
                <td>${emp.name}</td>
                <td>${emp.age}</td>
                <td>
                    <button>修改</button>
                    <button>删除</button>
                </td>
            </tr>
        </c:forEach>
    </table>

    <script>
        function add(){
            $.ajax({
                type:'post',
                data:$("#addform").serialize(),
                url:'/emp/add',
                success:function (res) {
                    if(res==true){
                        console.log("添加成功");
                        //刷新页面
                        window.document.location.reload();
                    }else {
                        console.log("添加失败");
                    }
                }
            })
        }
    </script>
</body>
</html>
